// run: $exec < bfdiff.in
#include <iostream>
#include <cmath>
#include <utility>

typedef std::pair<int, int> coord_type;

std::istream & operator>>(std::istream & is, coord_type & a)
{
	is >> a.first >> a.second;
	return is;
}

int const inf = 1 << 28;
coord_type da[3];
int n, dis;

int max_dis(coord_type const & a, coord_type const & b)
{
	return std::max(std::abs(a.first - b.first), std::abs(a.second - b.second));
}

bool on_edge(coord_type const & a, int step)
{
	return max_dis(a, da[2]) == step;
}

bool insquare(coord_type const & a, int step)
{
	return max_dis(a, da[2]) < step;
}

bool cross(coord_type const & a, coord_type const & b, int step)
{
	return (insquare(a, step) && !insquare(b, step)) || (insquare(b, step) && !insquare(a, step));
}

int check(coord_type const & a, coord_type const & b, int step)
{
	int dh = (a.second < b.second) ? 1 : -1; // direct horizontally
	for (int i = 1; i <= step; i++) {
		coord_type p[2];
		p[0].second = p[1].second = a.second + dh * i;
		p[0].first = std::max(1, std::max(a.first - i, b.first - (dis-i)));
		p[1].first = std::min(n, std::min(a.first + i, b.first + (dis-i)));
		if (on_edge(p[0], i) || on_edge(p[1], i) || cross(p[0], p[1], i))
			return i;
	}
	return inf;
}

int main()
{
	std::cin >> n;
	for (int i = 0; i < 3; i++) std::cin >> da[i];

	if (std::abs(da[0].first - da[1].first) > std::abs(da[0].second - da[1].second))
		for (int i = 0; i < 3; i++)
			std::swap(da[i].first, da[i].second);

	dis = std::abs(da[0].second - da[1].second);
	int ans = std::min(check(da[0], da[1], dis/2 - 1), check(da[1], da[0], dis/2 - 1));
	if (ans < inf)
		std::cout << "YES\n" << ans << '\n';
	else
		std::cout << "NO\n" << dis - 1 << '\n';
}

